package hanjia;

import java.util.Arrays;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/17-下午12:30
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode45 {

    public  static int jump(int[] nums) {

        if (nums.length== 1) {
            return 0;
        }

        int[] dp = new int[nums.length];
        Arrays.fill(dp,Integer.MAX_VALUE);
        dp[0]=0;
        for (int i=0;i<nums.length;i++){
            if (i+nums[i]>=nums.length-1){
                return dp[i]+1;
            }


               int j=1;
                while (j<=nums[i]&&i+j<dp.length){
                    dp[i+j]=Math.min(dp[i]+1,dp[i+j]);
                    j++;
                }




        }
        return -1;



    }

    public static void main(String[] args) {
       int [] nums = {2,3,1,1,4};
        System.out.println(jump(nums));
    }
}
